<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>后台</title>
    <link href="/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/dist/css/sb-admin-2.css" rel="stylesheet">
    <link href="/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-xs-4 col-xs-offset-4">
            <div class="login-panel panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">登录</h3>
                </div>
                <div class="panel-body">
                    <form id="login-form" role="form">
                        <fieldset>
                            <div class="form-group">
                                <input class="form-control" placeholder="账号" name="username" type="text" autofocus>
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="密码" name="password" type="password">
                            </div>
                            <button class="btn btn-lg btn-success btn-block" id="btn-submit-login" type="button">登录</button>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/vendor/jquery/jquery.min.js"></script>
<script>
    $('#btn-submit-login').click(function() {
        $.ajax({
            url: '/g-admin/login-handle',
            data: $('#login-form').serialize(),
            type: 'post',
            success: function(resp) {
                if (resp.code == 0) {
                    window.location.href = resp.data.href;
                } else {
                    alert(resp.msg || '暂时无法登录！');
                }
            },
            error: function(xhr) {
                console.log(xhr);
                alert('网络异常！');
            }
        });
    })
</script>
</body>
</html>
